package com.echronos.thirdsync.mq.AutoCount.handler;

import com.echronos.thirdsync.mq.AutoCount.message.AutoCountBaseMessage;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author wangyadong
 * @Date 2025/8/12 15:37
 * @ClassName AbstractMessageHandler
 */
@Slf4j
public abstract class AbstractMessageHandler implements AutoCountHandleStrategy {
    @Override
    public <T> void handle(AutoCountBaseMessage<T> message) {
        log.info("开始处理消息：{}，数据类型：{}，操作：{}",
                message.getMessageId(), message.getDataType(), message.getOperationType());
        try {
            // 调用具体实现的处理逻辑
            doHandle(message);
            log.info("消息处理成功：{}", message.getMessageId());
        } catch (Exception e) {
            log.error("消息处理失败：{}", message.getMessageId(), e);
            throw e; // 抛出异常，由上层处理重试/死信
        }
    }

    // 抽象方法：具体业务逻辑由子类实现
    protected abstract <T> void doHandle(AutoCountBaseMessage<T> message);
}
